/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tecbooks;

import javax.swing.JOptionPane;

/**
 *
 * @author ifal
 */
public class Locacao extends javax.swing.JFrame {

    /**
     * Creates new form Locacao
     */
    public Locacao() {
         setTitle("Locação");
         initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblNomeLocacao = new javax.swing.JLabel();
        lblDataSaida = new javax.swing.JLabel();
        lblDataEntrega = new javax.swing.JLabel();
        lblIDLivroLocacao = new javax.swing.JLabel();
        txtIDLivro = new javax.swing.JTextField();
        txtNomeLocacao = new javax.swing.JTextField();
        btnOkLocacao = new javax.swing.JButton();
        btnCancelarLocacao = new javax.swing.JButton();
        lblAvisoLocacao = new javax.swing.JLabel();
        cmbDiaLocacaoSaida = new javax.swing.JComboBox();
        cmbMesLocacaoSaida = new javax.swing.JComboBox();
        cmbDiaLocacaoEntrega = new javax.swing.JComboBox();
        cmbMesLocacaoEntrega = new javax.swing.JComboBox();
        cmbAnoLocacaosaida = new javax.swing.JComboBox();
        cmbAnoLocacaoEntrega = new javax.swing.JComboBox();
        lblAviso = new javax.swing.JLabel();
        btnVerificacaoLivro = new javax.swing.JButton();
        lblAvisoVerificacao = new javax.swing.JLabel();
        lblAvisoIdCliente = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        lblAviso1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lblNomeLocacao.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        lblNomeLocacao.setForeground(new java.awt.Color(21, 21, 11));
        lblNomeLocacao.setText("ID do cliente*:");
        getContentPane().add(lblNomeLocacao, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 170, -1, -1));

        lblDataSaida.setBackground(new java.awt.Color(255, 255, 255));
        lblDataSaida.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        lblDataSaida.setForeground(new java.awt.Color(21, 21, 11));
        lblDataSaida.setText("Data de saida(dd/mm/aaaa)*:");
        getContentPane().add(lblDataSaida, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 300, -1, 20));

        lblDataEntrega.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        lblDataEntrega.setForeground(new java.awt.Color(21, 21, 11));
        lblDataEntrega.setText("Data de entrega(dd/mm/aaaa)*:");
        getContentPane().add(lblDataEntrega, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 370, -1, -1));

        lblIDLivroLocacao.setFont(new java.awt.Font("Tahoma", 1, 15)); // NOI18N
        lblIDLivroLocacao.setForeground(new java.awt.Color(21, 21, 11));
        lblIDLivroLocacao.setText("ID Livro*:");
        getContentPane().add(lblIDLivroLocacao, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, 80, 30));

        txtIDLivro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIDLivroActionPerformed(evt);
            }
        });
        txtIDLivro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                apenasNumeros(evt);
            }
        });
        getContentPane().add(txtIDLivro, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 20, 259, -1));

        txtNomeLocacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNomeLocacaoActionPerformed(evt);
            }
        });
        txtNomeLocacao.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNomeLocacaoKeyTyped(evt);
            }
        });
        getContentPane().add(txtNomeLocacao, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 160, 220, 30));

        btnOkLocacao.setText("OK");
        btnOkLocacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOkLocacaoActionPerformed(evt);
            }
        });
        getContentPane().add(btnOkLocacao, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 460, -1, -1));

        btnCancelarLocacao.setText("Cancelar");
        btnCancelarLocacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarLocacaoActionPerformed(evt);
            }
        });
        getContentPane().add(btnCancelarLocacao, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 460, -1, -1));

        lblAvisoLocacao.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lblAvisoLocacao.setForeground(new java.awt.Color(255, 0, 0));
        getContentPane().add(lblAvisoLocacao, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 510, 360, 28));

        cmbDiaLocacaoSaida.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  ", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        getContentPane().add(cmbDiaLocacaoSaida, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 330, -1, -1));

        cmbMesLocacaoSaida.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  ", "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" }));
        getContentPane().add(cmbMesLocacaoSaida, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 330, 120, -1));

        cmbDiaLocacaoEntrega.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  ", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        getContentPane().add(cmbDiaLocacaoEntrega, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 410, -1, -1));

        cmbMesLocacaoEntrega.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  ", "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" }));
        getContentPane().add(cmbMesLocacaoEntrega, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 410, 120, -1));

        cmbAnoLocacaosaida.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  ", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));
        getContentPane().add(cmbAnoLocacaosaida, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 330, -1, -1));

        cmbAnoLocacaoEntrega.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  ", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));
        getContentPane().add(cmbAnoLocacaoEntrega, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 410, -1, -1));

        lblAviso.setFont(new java.awt.Font("Tunga", 1, 24)); // NOI18N
        lblAviso.setForeground(new java.awt.Color(255, 0, 0));
        lblAviso.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        getContentPane().add(lblAviso, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 200, 430, 70));

        btnVerificacaoLivro.setText("Buscar Livros");
        btnVerificacaoLivro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVerificacaoLivroActionPerformed(evt);
            }
        });
        getContentPane().add(btnVerificacaoLivro, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 20, -1, -1));

        lblAvisoVerificacao.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lblAvisoVerificacao.setForeground(new java.awt.Color(255, 0, 0));
        getContentPane().add(lblAvisoVerificacao, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 120, 260, 30));

        lblAvisoIdCliente.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lblAvisoIdCliente.setForeground(new java.awt.Color(255, 0, 0));
        getContentPane().add(lblAvisoIdCliente, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 270, 350, 30));

        jButton1.setText("Buscar Cliente");
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 160, -1, -1));

        lblAviso1.setFont(new java.awt.Font("Tunga", 1, 24)); // NOI18N
        lblAviso1.setForeground(new java.awt.Color(255, 0, 0));
        lblAviso1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        getContentPane().add(lblAviso1, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 60, 430, 70));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnOkLocacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkLocacaoActionPerformed
     if (txtIDLivro.getText().isEmpty() || txtNomeLocacao.getText().isEmpty() || cmbDiaLocacaoSaida.getSelectedItem().equals("  ") ||
             cmbMesLocacaoSaida.getSelectedItem().equals("  ")||cmbAnoLocacaosaida.getSelectedItem().equals("  ")||cmbDiaLocacaoEntrega.getSelectedItem().equals("  ")
             ||cmbMesLocacaoEntrega.getSelectedItem().equals("  ")||cmbAnoLocacaoEntrega.getSelectedItem().equals("  ")) {
            lblAvisoLocacao.setText("Preencha os campos obrigatórios!");
            
        } else {
            JOptionPane.showMessageDialog(null, "Locação realizada!");        // TODO add your handling code here:
     }
    }//GEN-LAST:event_btnOkLocacaoActionPerformed

    private void btnCancelarLocacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarLocacaoActionPerformed
        dispose();
        TelaPrincipal tela = new TelaPrincipal();
        tela.setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_btnCancelarLocacaoActionPerformed

    private void apenasNumeros(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_apenasNumeros
     String numeros = "0123456789";
        if(!numeros.contains(evt.getKeyChar()+"") && (int)evt.getKeyChar() != 8){
            evt.consume();
            lblAviso.setText("Por favor, informe apenas números!");
        }
        else{
           lblAviso.setText("");
        }
    
    
      
    }//GEN-LAST:event_apenasNumeros

    private void txtIDLivroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIDLivroActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtIDLivroActionPerformed

    private void btnVerificacaoLivroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerificacaoLivroActionPerformed
        if (txtIDLivro.getText().equals("123456")){
            PedidoDeReserva pedido = new PedidoDeReserva();
            pedido.setVisible(true);
        } else {
            lblAvisoVerificacao.setText("Livro disponível! Continue!");
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_btnVerificacaoLivroActionPerformed

    private void txtNomeLocacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNomeLocacaoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNomeLocacaoActionPerformed

    private void txtNomeLocacaoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNomeLocacaoKeyTyped
        // TODO add your handling code here:
            String numeros = "0123456789";
        if(!numeros.contains(evt.getKeyChar()+"") && (int)evt.getKeyChar() != 8){
            evt.consume();
            lblAvisoIdCliente.setText("Por favor, informe apenas números!");
        }
        else{
           lblAvisoIdCliente.setText("");
        }
    }//GEN-LAST:event_txtNomeLocacaoKeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Locacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Locacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Locacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Locacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Locacao().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelarLocacao;
    private javax.swing.JButton btnOkLocacao;
    private javax.swing.JButton btnVerificacaoLivro;
    private javax.swing.JComboBox cmbAnoLocacaoEntrega;
    private javax.swing.JComboBox cmbAnoLocacaosaida;
    private javax.swing.JComboBox cmbDiaLocacaoEntrega;
    private javax.swing.JComboBox cmbDiaLocacaoSaida;
    private javax.swing.JComboBox cmbMesLocacaoEntrega;
    private javax.swing.JComboBox cmbMesLocacaoSaida;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel lblAviso;
    private javax.swing.JLabel lblAviso1;
    private javax.swing.JLabel lblAvisoIdCliente;
    private javax.swing.JLabel lblAvisoLocacao;
    private javax.swing.JLabel lblAvisoVerificacao;
    private javax.swing.JLabel lblDataEntrega;
    private javax.swing.JLabel lblDataSaida;
    private javax.swing.JLabel lblIDLivroLocacao;
    private javax.swing.JLabel lblNomeLocacao;
    private javax.swing.JTextField txtIDLivro;
    private javax.swing.JTextField txtNomeLocacao;
    // End of variables declaration//GEN-END:variables
}
